package util.pagingOpt.impl;

import dao.admins.impl.SellerQueryImpl;
import pojo.Seller;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class PagingImpl extends Paging{

    public PagingImpl(int pageSize, String sqlCount, String sqlQuery) {
        super(pageSize, sqlCount, sqlQuery);
    }

    @Override
    public List<Seller> getList() {
        return queryList();
    }


    private  List<Seller> queryList(){
        List<Seller> sellers = new ArrayList<>();
        Object[] params = {(pageEntity.getCurrentPage() - 1) * pageEntity.getPageSize(), pageEntity.getPageSize()};
        try(ResultSet rs = baseDao.executeSelect(sqlPaging, params)){
            while (rs.next()){
                Seller seller = new Seller();
                SellerQueryImpl.setSeller(seller, rs.getLong("id"), rs.getString("sellerName"), rs.getString("sellerUser"), rs.getString("sellerPassword"), rs.getString("sellerSex"),
                        rs.getTimestamp("sellerBirthday"), rs.getString("sellerIdCard"), rs.getString("sellerEmail"), rs.getString("sellerTel"), rs.getString("sellerAddress"));
                sellers.add(seller);
            }
            baseDao.closeAll();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return sellers;
    }
}
